package org.jianfa.learn.jpa.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        if (!"admin".equals(name) || !"admin".equals(password)) {
            request.setAttribute("login", Boolean.FALSE);
        } else {
            request.setAttribute("login", Boolean.TRUE);
        }

        return true;
    }
}
